﻿{$header}

<php>
function getActionButton($id){
    $sod = M('Buy');
    $sod ->getById($id);
    $status = $sod->status;
    switch($status){
        case 0:     //待确定
            echo "<form action='__URL__/Update' method='post' id='form_status' name='form_status'>
              <input type='hidden' value='".$id."' name='id'>
              <input type='hidden' name='status' value='1'>
              <a href='#' onclick='javascript:setNewValue(".$id.",1)' class='btn btn-primary'>开始议价</a>
             </form> ";
            break;
        case 1:    //询价中
            if($sod->supplier_id > 0)
            echo "
            <form action='__URL__/Update' method='post' id='form_status' name='form_status'>
              <input type='hidden' value='".$id."' name='id'>
              <input type='hidden' name='status' value='2'>
              <input type='hidden' value='__SELF__' name='jumpUrl'>
            <a href='#' onclick='javascript:setNewValue(".$id.",2)' class='btn btn-primary'>签订合同</a>
          </form>";
            break;
        case 2:     //已签订合同
            echo "
            <form action='__URL__/Update' method='post' id='form_status' name='form_status'>
              <input type='hidden' value='".$id."' name='id'>
              <input type='hidden' value='__SELF__' name='jumpUrl'>
              <input type='hidden' name='status' value='3'>
            <a href='#' onclick='javascript:setNewValue(".$id.",3)' class='btn btn-primary'>供方货存产品，正在出库</a></form> | 
            <form action='__URL__/Update' method='post' id='form_status' name='form_status'>
              <input type='hidden' value='".$id."' name='id'>
              <input type='hidden' name='status' value='4'>
              <input type='hidden' value='__SELF__' name='jumpUrl'>
            <a href='#' onclick='javascript:setNewValue(".$id.",4)' class='btn btn-primary'>供方订制产品，开始订制</a></form>";
            break;
        case 3:     
        case 4:     //准备发货
           echo "
           <form action='__URL__/Update' method='post' id='form_status' name='form_status'>
              <input type='hidden' value='".$id."' name='id'>
              <input type='hidden' name='status' value='5'>
              <input type='hidden' value='__SELF__' name='jumpUrl'>
           <a href='#' onclick='javascript:setNewValue(".$id.",5)' class='btn btn-primary'>供方已经发货</a></form>";
            break;
        default:
            echo "---";
}
}
</php>
<div id="main" class="main" >
    <div class="content">
  <h3 class="heading">编辑采购单 [ <a href="__URL__">返回列表</a> ]
    <div class="btn-group pull-right">
      <button class="btn btn-primary" onclick="drop_buy({$vo.id})"><i class="icon-user icon-white"></i> 作废采购订单</button>
      <button class="btn btn-primary" onclick="create_consign({$vo.id})"><i class="icon-user icon-white"></i> 生成采购合同</button>
     <a href="__PUBLIC__/Downloads/buy/采购合同_{$vo.order_detail_id|getModelName='Order_detail','mano'}.docx">下载采购合同</a>
    </div>
  </h3>
<div id="result" class="result none"></div>

<table cellpadding=3 cellspacing=3 >
<tr>
    <td>销售订单号</td><td><a href="__APP__/Order/detail/id/{$vo.order_id}"> {$vo.order_id|getModelName='Order','mano'} </a>
    <span class="offset1">{$vo.id|getActionButton}</span>
    </td>
</tr>
<tr>
    <td width="150px">采购单号：</td>
  <td>
            {$vo.mano}
            <span class="offset1">采购时间：</span> {$vo.create_time|toDate}
            &nbsp;&nbsp;状态：{$vo.status|getConfigVal='buyStatus'}
        </td>
</tr>
<form class="form-horizontal well" method='post' id="form1" name="form1" action="__URL__/update/">
<tr>
     <td>异常管理</td>
     <td> {$vo.exception_status|getConfigVal='exceptionStatus'}
                <?php $orderStatus = C('exceptionStatus');
            unset($orderStatus[ array_search('退款成功', $orderStatus) ]);
            unset($orderStatus[ array_search('换货合格', $orderStatus) ]);
            unset($orderStatus[ array_search('退纯合格', $orderStatus) ]);
            ?>
            {:configList($orderStatus,$vo['exception_status'],'exception_status')}
     </td>
 </tr>
<tr>
  <td>负责人</td><td>{$vo.charge_man|getModelName='User'}</td>
</tr>

<tr>
    <td class="tRight" width="150px">供应商：</td>
    <td class="tLeft" >
            <div class="input-append">
              <!--用于新增供应商时，返回供应商参数-->
                <input id="cq" name="cq" class="input-xlarge search-query" 

                <notempty name='_REQUEST.supplier_id'>value="{$_REQUEST.supplier_id|getModelName='Supplier'}"
                <else/>
                    value="{$vo.supplier_id|getModelName='Supplier'}"
                </notempty>
                >
                <input id="hz" name="supplier_id" type="hidden" 
                <notempty name='_REQUEST.supplier_id'> value="{$_REQUEST.supplier_id}"
                    <else/>
                    value="{$vo.supplier_id}"
                 </notempty>
                 >
                <button class="btn" type="button" onclick="filterSupplier()"><i class="icon-search"></i>
                <notempty name="vo.supplier_id">
                 变更供应商<else/> 搜索
                </notempty>  
                </button>
            </div>
            <a class="btn" href="__APP__/Supplier/add/return/Buy/rid/{$_REQUEST.id}"><i class="icon-user"></i>
                <notempty name="vo.supplier_id">
                 新增变更供应商<else/> 新增供应商
                </notempty></a>  
        <button class="btn" type="button" onClick="filterInquiry({$vo.product_id})">从询价中选择供应商</button>
        
        </td>
</tr>
<tr>
  <?php $count_buys = M('Buy')->where('supplier_id = '.$vo['supplier_id']) ->count(); ?>
  <td>合作记录及联系方式</td> <td> <a href="__APP__/Supplier/edit/id/{$vo.supplier_id}#buy" target="_blank">合作记录({$count_buys})</a>  <a class="offset1" href="__APP__/Supplier/edit/id/{$vo.supplier_id}" target="_blank">联系方式</a> 
   </td>
</tr>
  <tr>
    <td>产品</td>
    <td>
        {$vo.product_id|getModelName='Product'}
        <span class="offset1">{$vo.product_id|getPename}</span>
        <span class="offset1">{$vo.product_id|getCas}</span>
        <span class="offset1"> <a href="__APP__/Product/buy/id/{$vo.product_id}" target="_blank"> 采购记录</a> </span>
        <img src="__PUBLIC__/Uploads/product/{$vo.product_id|getCas}.jpg">
    </td>
  </tr>
<tr>
    <td>询价负责人</td>
    <td><input type="hidden" name="ask_charge_man" value="{$vo.ask_charge_man}" />{$vo.ask_charge_man|getModelName='User'} </td>
</tr>    
  <empty name="vo.order_id"><else />
    <tr>
     <td>单位成本</td><td>{$vo.order_detail_id|getModelName='Order_detail','cost'} 元 <span class="label label-important">采购单价不得高于单位成本</span> </td>
 </tr>
  </empty>

 <tr>
     <td>单价</td><td>
     <input type="text" name='price' value="{$vo.price}">元
     <strong>规格</strong> {$vo.specification|modList='Specification',###,'span3','specification'}</td>
 </tr>
<tr>
     <td>数量</td><td>
     <input type="text" name='number' value="{$vo.number}">{$vo.product_id|getProductUnit}</td>
 </tr>
<tr>
     <td>总价</td>
     <td>{$vo.total}元 </td>
 </tr>
 <tr>
     <td>要求交货期</td><td>
     <input type="text" name='delivery_date' value="{$vo.delivery_date|toDate='Y-m-d'}" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"></td>
 </tr>

 <tr>
     <td>结算方式</td>
     <td>{:configList(C('settle_method'),$vo['settle_method'],'settle_method')}
        预付款<input type="text" name="to_first_pay" value="{$vo.to_first_pay}">
        余款{$vo.to_remain_pay} 元
         
     </td>
 </tr>
 <tr>
     <td>财务操作情况</td>
     <td>
        已经支付预付:{$vo.first_pay}元
        <span class="offset1">已经支付余款:{$vo.remain_pay}元</span>
        <span class="offset1">实际付款:{$vo.real_pay}元</span>
     </td>
 </tr>
 <tr>
     <td>快递公司</td>
     <td>
        <select class="middle bLeft"  name="logi_id">
                <volist name="logicompany" id="os">
                    <option value="{$key}" <eq name="vo.logi_id" value="$key">selected</eq> >{$os}</option>
                </volist>
            </select>
        快递单号：<input type="text" name="logi_no" value="{$vo.logi_no}">
        运费 :<input type="text" name="logifee" value="{$vo.logifee}">
     </td>
 </tr>
 <tr>
    <td>预计到货期</td>
    <td><input type="text" name='expect_date' value="{$vo.expect_date|toDate='Y-m-d'}" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"></td>
</tr>
<tr>
  <td>是否有样品</td>
  <td> <select name="with_sample">
      <option value="待确认" <eq name="vo.with_sample" value="待确认">selected</eq> >待确认</option>
      <option value="有" <eq name="vo.with_sample" value="有">selected</eq> >有</option>
      <option value="无" <eq name="vo.with_sample" value="无">selected</eq> >无</option>
   </select> 
   样品物流信息 <input type="text" name="sample_loginfo" value="{$vo.sample_loginfo}" >
  </td>
</tr>
<tr>
  <td class="tRight" >经办人：</td>
  <td class="tLeft" >{:modList('User')}
        </td>
</tr>
<tr>
    <td>供应商资质</td>
    <td>
        <input type="checkbox" name="three_license" <eq name="vo.three_license" value="1">checked</eq> >供方三证
        <input type="checkbox" name="analysis_sheet" <eq name="vo.analysis_sheet" value="1">checked</eq> >分析单
        <input type="checkbox" name="sign_contract" <eq name="vo.sign_contract" value="1">checked</eq> >合同签订
        <input type="checkbox" name="invoice" <eq name="vo.invoice" value="1">checked</eq> >是否开票
        <input type="checkbox" name="shipping_notice" <eq name="vo.shipping_notice" value="1">checked</eq> >发货须知
    </td>
</tr>
<tr>
  <td class="tRight">备注：</td>
        <td class="tLeft"><textarea class="span12" name="remark" rows="4">{$vo.remark}</textarea>
        </td>
</tr>
<tr>
	<td></td>
	<td class="center" width="300">
    <input name="jumpUrl" type="hidden" value="__SELF__" />
        <input type="hidden" value="{$vo.id}" name="id">
	<button type="submit" class="btn btn-primary"><i class="icon-ok icon-white"></i> 保存</button>
	<button type="reset" onclick="javascript:history.back()" class="btn btn-primary offset1"><i class="icon-arrow-left icon-white"></i> 返回</button>
	</td>
</tr>
<tr>
    <td colspan="2" class="alert alert-info">其他信息</td>
</tr>
<tr>
    <td>入库质量控制</td><td>{$vo.in_qc_status|getConfigVal='inQcStatus'}</td>
</tr>
<tr>
    <td>货前样质量控制</td><td>{$vo.sample_qc_status|getConfigVal='sampleQcStatus'}
     <p>样品送检时间：{$vo.sample_to_test_time|toDate}</p>
     <p>样品收到时间：{$vo.sample_got_time|toDate}</p>

    </td>
</tr>
<tr>
    <td>付款状态</td><td>{$vo.pay_status|getConfigVal='payStatus'}</td>
</tr>
<tr>
    <td>收货信息</td>
    <td>收货数量：{$vo.receive_number} <strong>收货人：</strong>{$vo.receive_user|getModelName='User'}  <strong>收货时间：</strong>{$vo.receive_time|toDate} </td>
</tr>
</table>
</form>
<notempty name="vo.order_detail_id">
<?php 
$msgs = M('Message')->where('obj_type="Order_detail" and obj_id ='.$vo['order_detail_id'])->order('create_time desc')->findAll();
        
 ?>
<table class="table table-bordered">
  <tr class="alert alert-info"><td colspan=5>订单备注</td>
    <td><a class="btn btn-primary" href="__APP__/Message/add/obj_type/Order_detail/depart/采购/obj_id/{$vo.order_detail_id}/return_type/Buy/return_id/{$vo.id}"><i class="icon-comment icon-white"></i> 创建备注</a></td> 
  </tr>
  <tr> <td>编号</td><td>部门</td><td>留言</td><td>操作人</td>  <td>日期</td><td>修改</td> </tr>
  <!--order by create time desc-->
  <volist name="msgs" id="msg">
    <eq name="_SESSION[C('USER_AUTH_KEY')]" value="$msg.user_id"> 
      <form action="__APP__/Message/update" method="post" id="msg"
      <tr>
        <td> <input type="hidden" name="id" value="{$msg.id}">
          <input type="hidden" name="jumpUrl" value="__SELF__">
          {$msg.id}</td>
        <td>{$msg.depart}</td>
        <td><textarea name="content" class="input-xxlarge" rows="4">{$msg.content}</textarea> </td>
        <td>{$msg.user_id|getModelName='User'}</td>
        <td>{$msg.create_time|toDate}</td>
        <td> <input type="submit" class="btn btn-primary" value="修改"> </td>
      </tr>
      </form>
    <else/>
    <tr>
      <td>{$msg.id}</td>
      <td>{$msg.depart}</td>
      <td>{$msg.content}</td>
      <td>{$msg.user_id|getModelName='User'}</td>
      <td>{$msg.create_time|toDate}</td>
      <td> ---</td>
    </tr>
  </eq>
  </volist>
</table>
</notempty>

</div>
</div>
<include file="Public:footer" />
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/easyui/themes/default/easyui.css">
<script type="text/javascript" src="__PUBLIC__/Js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/filter-product.js"></script>
<load href="__PUBLIC__/Js/My97DatePicker/WdatePicker.js" />
<script type="text/javascript">
    function setNewValue(id,newValue){
        if (window.confirm('确定要推进采购进度吗？'))
        {
            $('#form_status').submit();
        }else
          return false;
    }

    function drop_buy(id){
        if (window.confirm('确定要作废采购订单吗？'))
        {
            location.href=URL+"/setFieldValue/id/"+id+"/field/status/new/10";
        }else
          return false;
    }
    function create_consign(id){
         location.href = URL+ "/createBuyConsign/id/"+id;    
    }
</script>
